<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>refs练习</title>
</head>
<body>
  <div id="test"></div>

  <!-- 引入库：先引入核心库，再引入操作DOM的扩展库 -->
  <script type="text/javascript" src="../js/react.development.js"></script>
  <script type="text/javascript" src="../js/react-dom.development.js"></script>
  <!-- 将jsx转为js -->
  <script type="text/javascript" src="../js/babel.min.js"></script>
  <script type="text/babel">    //必须写babel，因为默认js
    class Demo extends React.Component{
      showData = ()=>{
        const {input1} = this
        console.log(this)
        alert(input1.value)
      }

      showData2 = ()=>{
        const {input2} = this
        alert(input2.value)
      }

      render(){
        return (
          <div>
            <input ref={(c) => {this.input1 = c}} type="text" placeholder='点击按钮提示数据 '/>
            <button onClick={this.showData}>点我提示left数据</button>&nbsp;
            <input ref={c => this.input2 = c} onBlur={this.showData2} type="text" placeholder='失去焦点提示数据'/>
          </div>
        )
      }
    }

    ReactDOM.render(<Demo/>, document.getElementById('test'))
  </script>
</body>
</html>